/**
 * Created by dale on 2017/8/8.
 */
$(document).ready(function () {
    var form=$('#form');
    var $form=new xhForm(form);
    var $icuId=xhTool.getQuery('icuId');
    $('[name="iCUId"]').val($icuId);//设置客户id

    $('[name="sSubjects[]"]').select2();
    $('[name="sGrades[]"]').select2();
    var $icucId=xhTool.getQuery('icucId');
    if($icucId!=null){

        xhExtra.ajaxRequest('school_contact/getContactData',{'iCUCId':$icucId},null,function (data) {
            $form.fill(data);
            if(data['sSubjects'] != null){
                $('[name="sSubjects[]"]').val(data['sSubjects'].split(',')).trigger('change');
            }
            if(data['sGrades'] != null){
                $('[name="sGrades[]"]').val(data['sGrades'].split(',')).trigger('change');
            }
            form.initeValidate($('#bt_modal_confirm',parent.document));
        })
    }else {
        $('#bt_modal_confirm',parent.document).addClass('disabled');
        form.initeValidate($('#bt_modal_confirm',parent.document));
    }

    
    $('#bt_modal_confirm',parent.document).click(function () {
        //form.submit();
        $form.submit('school_contact/saveContact',{},function (data) {
            window.top.xhTop.getActiveFrame().frames['contactFrame'].location.reload();
            window.top.xhTop.closeModal();
        })

    });

    modalBind.bindClick();
    
    
});